/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package course.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author def
 */
@Entity
@Table(name = "images")
@SequenceGenerator(sequenceName = "global_seq", name = "global_seq")
@NamedQueries({@NamedQuery(name = "Image.findAll", query = "SELECT i FROM Image i")})
public class Image implements Serializable {

    private static final long serialVersionUID = -8595423119846L;

    @Id
    @Column(name = "image_id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private long id;
    
    @Column(name = "image_name")
    private String name;

    @Lob
    @Column(name = "image_file")
    @Basic(fetch = FetchType.EAGER)
    private byte[] imageFile;

    public Image() {
    }
    
    public Image(String name, byte[] imageFile) {
        this.name = name;
        this.imageFile = imageFile;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        if(name.contains(" ")) {
           return name.substring(name.indexOf(" "));
        }
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public byte[] getImageFile() {
        return imageFile;
    }

    public void setImageFile(byte[] imageFile) {
        this.imageFile = imageFile;
    }
    
}
